package system

import (
	"data-center/pkg/queue"
	"net/http"

	"github.com/gin-gonic/gin"
	"go.mongodb.org/mongo-driver/mongo"
	"gorm.io/gorm"
)

// Handler 任务处理器
type Handler struct {
	// 注入服务依赖
	db       *gorm.DB
	mongo    *mongo.Collection
	producer queue.Producer
}

// NewHandler 创建任务处理器
func NewHandler(db *gorm.DB, mongoClient *mongo.Collection, producer queue.Producer) *Handler {
	return &Handler{
		db:       db,
		mongo:    mongoClient,
		producer: producer,
	}
}

// RegisterRoutes 注册路由
func (h *Handler) RegisterRoutes(r *gin.RouterGroup) {
	system := r.Group("/system")
	{
		system.GET("/metrics", h.GetMetrics)
		system.GET("/status", h.GetStatus)
	}

	// 健康检查路由通常放在根路径
	r.GET("/health", h.HealthCheck)
}

// GetMetrics 获取系统指标
func (h *Handler) GetMetrics(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{"message": "Metrics data"})
}

// GetStatus 获取系统状态
func (h *Handler) GetStatus(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{"message": "System status"})
}

// HealthCheck 健康检查
func (h *Handler) HealthCheck(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{"status": "ok"})
}
